Skip to content

Add gpio_init_mask64 function#2907

Open
FLyrfors-MI wants to merge 6 commits intoraspberrypi:developfrom
FLyrfors-MI:gpio_init_mask64
Open

Add gpio_init_mask64 function#2907
FLyrfors-MI wants to merge 6 commits intoraspberrypi:developfrom
FLyrfors-MI:gpio_init_mask64

Conversation

@FLyrfors-MI
Copy link
Copy Markdown

Add gpio_init_mask64 function mirroring the other mask64/masked64 GPIO functions used by RP2350B with more than 32 GPIO's.

See #2643

Comment thread src/rp2_common/hardware_gpio/include/hardware/gpio.h Outdated
Comment thread src/rp2_common/hardware_gpio/gpio.c Outdated
Comment thread src/rp2_common/hardware_gpio/gpio.c Outdated
kilograham and others added 3 commits May 9, 2026 13:45
Co-authored-by: Andrew Scheller <lurch@durge.org>
Early out on no remaining bits in mask for no code cost vs the MIN() version
Also optimize the 64 bit methods for NUM_BANK0_GPIOS <= 32
@kilograham kilograham requested review from lurch and will-v-pi May 9, 2026 19:27
@kilograham kilograham added this to the 2.2.1 milestone May 9, 2026
Comment on lines 316 to 324
void gpio_set_function_masked(uint32_t gpio_mask, gpio_function_t fn) {
for (uint i = 0; i < MIN(NUM_BANK0_GPIOS, 32u); i++) {
for (uint i = 0; i < NUM_BANK0_GPIOS; i++) {
if (gpio_mask & 1u) {
gpio_set_function(i, fn);
}
gpio_mask >>= 1;
if (!gpio_mask) break;
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only a small optimisation, but is it worth doing:

void gpio_set_function_masked(uint32_t gpio_mask, gpio_function_t fn) {
    if (gpio_mask) {
        for (uint i = 0; i < NUM_BANK0_GPIOS; i++) {
            if (gpio_mask & 1u) {
                gpio_set_function(i, fn);
            }
            gpio_mask >>= 1;
            if (!gpio_mask) break;
        }
    }
}

(or is it better to assume that this function will never be called with an empty gpio_mask?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants